package index;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import shopping.Dish;

import java.io.IOException;
import java.util.List;

@WebServlet("/AdminDishListServlet")
public class AdminDishListServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        // 权限检查
        HttpSession session = request.getSession(false);
        if (session == null || !"admin".equals(session.getAttribute("role"))) {
            response.sendRedirect("loginRegister.jsp");
            return;
        }

        List<Dish> dishes = JdbcUtils.getAllDishes();
        request.setAttribute("dishes", dishes);
        request.getRequestDispatcher("/adminDishList.jsp").forward(request, response);
    }
}
